from django.http import HttpResponseRedirect
from django.shortcuts import render

# Create your views here.
from django.views import View

from contents.models import ContentCategory
from goods.models import GoodsChannelGroup
from goods.utils import get_categories


class IndexView(View):
    def get(self, request):

        data = get_categories()

        contents = {}

        # 6, 拿到所有的分类

        categories = ContentCategory.objects.all()
        # 7, 再把每个分类下面的内容取到
        for cat in categories:
            contents[cat.key] = cat.content_set.filter(status=True).order_by('sequence')

        context = {
            "categories": data,
            "contents": contents
        }

        return render(request, 'index.html', context=context)
